package edu.hawaii.duedates.libraries;

import static org.junit.Assert.assertEquals;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Formatter;
import java.util.Locale;
import org.junit.Test;

/**
 * Test cases for the LibraryBook class.
 * 
 * @author Ka Hung Phillip Lau
 * @author Creighton Okada
 *
 */
public class TestLibraryBook {
  /**
   * Test getBookTitle method.
   */
  @Test
  public void testLibraryBookCreation() {
    final String title = "Book Title";
    final Date dueDate = new Date();
    DateFormat newFormat = new SimpleDateFormat("MM/dd/yyyy", Locale.US);
    
    LibraryBook book = new LibraryBook(title, dueDate);
    
    assertEquals("Testing the getBookTitle method.  Should return 'Book Title'.", "Book Title",
        book.getBookTitle());
    String date = newFormat.format(dueDate);
    assertEquals("Testing the getBookDueDate method.  Should return today's date.", 
        date, newFormat.format(book.getBookDueDate()));
    
    StringBuilder outputString = new StringBuilder();
    Formatter formatter = new Formatter(outputString);
    String format = "|%-70.70s\t|%-10s|\n";
    formatter.format(format, title, newFormat.format(dueDate));
    
    assertEquals("Testing the toString method.", outputString.toString(), book.toString());
  }
}
